Probably solve http://bugzilla.wikipedia.org/show_bug.cgi?id=733
[lhc/web/wiklou.git] / config / index.php
1 <?php
2 # MediaWiki web-based config/installation
3 # Copyright (C) 2004 Brion Vibber <brion@pobox.com>
4 # http://www.mediawiki.org/
5 #
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License along
17 # with this program; if not, write to the Free Software Foundation, Inc.,
18 # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 # http://www.gnu.org/copyleft/gpl.html
20
21 error_reporting( E_ALL );
22 header( "Content-type: text/html; charset=utf-8" );
23 @ini_set( "display_errors", true );
24
25 ?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
26 "http://www.w3.org/TR/html4/loose.dtd">
27 <html>
28 <head>
29 <meta http-equiv="Content-type" content="text/html; charset=utf-8">
30 <meta name="robots" content="noindex,nofollow">
31 <title>MediaWiki installation</title>
32 <style type="text/css">
33 #credit {
34 float: right;
35 width: 200px;
36 font-size: 0.7em;
37 background-color: #eee;
38 color: black;
39 border: solid 1px #444;
40 padding: 8px;
41 margin-left: 8px;
42 }
43
44 dl.setup dd {
45 margin-left: 0;
46 }
47 dl.setup dd label.column {
48 clear: left;
49 font-weight: bold;
50 width: 12em;
51 float: left;
52 text-align: right;
53 padding-right: 1em;
54 }
55 dl.setup dt {
56 clear: left;
57 font-size: 0.8em;
58 margin-left: 10em;
59 /* margin-right: 200px; */
60 margin-bottom: 2em;
61 }
62 .error {
63 color: red;
64 }
65 ul.plain {
66 list-style: none;
67 clear: both;
68 margin-left: 12em;
69 }
70 </style>
71 </head>
72
73 <body>
74
75 <div id="credit">
76 <center>
77 <a href="http://www.mediawiki.org/"><img
78 src="../skins/common/images/wiki.png" width="135" height="135" alt="" border="0" /></a>
79 </center>
80
81 <b><a href="http://www.mediawiki.org/">MediaWiki</a></b> is
82 Copyright (C) 2001-2004 by Magnus Manske, Brion Vibber, Lee Daniel Crocker,
83 Tim Starling, Erik M&ouml;ller, Gabriel Wicke and others.</p>
84
85 <ul>
86 <li><a href="../README">Readme</a></li>
87 <li><a href="../RELEASE-NOTES">Release notes</a></li>
88 <li><a href="../docs/">doc/</a></li>
89 <li><a href="http://meta.wikipedia.org/wiki/MediaWiki_User's_Guide">User's Guide</a></li>
90 </ul>
91
92 <p>This program is free software; you can redistribute it and/or modify
93 it under the terms of the GNU General Public License as published by
94 the Free Software Foundation; either version 2 of the License, or
95 (at your option) any later version.</p>
96
97 <p>This program is distributed in the hope that it will be useful,
98 but WITHOUT ANY WARRANTY; without even the implied warranty of
99 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
100 GNU General Public License for more details.</p>
101
102 <p>You should have received <a href="../COPYING">a copy of the GNU General Public License</a>
103 along with this program; if not, write to the Free Software
104 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
105 or <a href="http://www.gnu.org/copyleft/gpl.html">read it online</a></p>
106 </div>
107
108 <?php
109
110 $IP = ".."; # Just to suppress notices, not for anything useful
111 define( "MEDIAWIKI", true );
112 define( "MEDIAWIKI_INSTALL", true );
113 require_once( "../includes/Defines.php" );
114 require_once( "../includes/DefaultSettings.php" );
115 require_once( "../includes/MagicWord.php" );
116 require_once( "../includes/Namespace.php" );
117 ?>
118
119 <h1>MediaWiki <?php print $wgVersion ?> installation</h1>
120
121
122 <?php
123
124 /* Check for existing configurations and bug out! */
125
126 if( file_exists( "../LocalSettings.php" ) || file_exists( "../AdminSettings.php" ) ) {
127 dieout( "<h2>Wiki is configured.</h2>
128
129 <p>Already configured... <a href='../index.php'>return to the wiki</a>.</p>
130
131 <p>(You should probably remove this directory for added security.)</p>" );
132 }
133
134 if( file_exists( "./LocalSettings.php" ) || file_exists( "./AdminSettings.php" ) ) {
135 dieout( "<h2>You're configured!</h2>
136
137 <p>Please move <tt>LocalSettings.php</tt> to the parent directory, then
138 <a href='../index.php'>try out your wiki</a>.
139 (You should remove this config directory for added security once you're done.)</p>" );
140 }
141
142 if( !is_writable( "." ) ) {
143 dieout( "<h2>Can't write config file, aborting</h2>
144
145 <p>In order to configure the wiki you have to make the <tt>config</tt> subdirectory
146 writable by the web server. Once configuration is done you'll move the created
147 <tt>LocalSettings.php</tt> to the parent directory, and for added safety you can
148 then remove the <tt>config</tt> subdirectory entirely.</p>
149
150 <p>To make the directory writable on a Unix/Linux system:</p>
151
152 <pre>
153 cd <i>/path/to/wiki</i>
154 chmod a+w config
155 </pre>" );
156 }
157
158
159 require_once( "../install-utils.inc" );
160 require_once( "../maintenance/updaters.inc" );
161 require_once( "../maintenance/convertLinks.inc" );
162 require_once( "../maintenance/archives/moveCustomMessages.inc" );
163
164 class ConfigData {
165 function getEncoded( $data ) {
166 # Hackish
167 global $wgUseLatin1;
168 if( $wgUseLatin1 ) {
169 return utf8_decode( $data ); /* to latin1 wikis */
170 } else {
171 return $data;
172 }
173 }
174 function getSitename() { return $this->getEncoded( $this->Sitename ); }
175 function getSysopName() { return $this->getEncoded( $this->SysopName ); }
176 function getSysopPass() { return $this->getEncoded( $this->SysopPass ); }
177 }
178
179 ?>
180
181 <p><i>Please include all of the lines below when reporting installation problems.</i></p>
182
183 <h2>Checking environment...</h2>
184 <ul>
185 <?php
186 $endl = "
187 ";
188 $wgConfiguring = true;
189 $conf = new ConfigData;
190
191 install_version_checks();
192
193 print "<li>PHP " . phpversion() . ": ";
194 if( version_compare( phpversion(), "5.0", "lt" ) ) {
195 print "ok";
196 } else {
197 print " <b>the MonoBook skin will be disabled due to an incompatibility
198 between the PHPTAL template library and PHP 5</b>. The wiki should
199 function normally, but with the older look and feel.";
200 }
201 print "</li>\n";
202
203 if( ini_get( "register_globals" ) ) {
204 ?>
205 <li><b class='error'>Warning:</b> <b>PHP's
206 <tt><a href="http://php.net/register_globals">register_globals</a></tt>
207 option is enabled.</b> MediaWiki will work correctly, but this setting
208 increases your exposure to potential security vulnerabilities in PHP-based
209 software running on your server. <b>You should disable it if you are able.</b></li>
210 <?php
211 }
212
213 if( ini_get( "safe_mode" ) ) {
214 ?>
215 <li class='error'><b>Warning: PHP's
216 <a href='http://www.php.net/features.safe-mode'>safe mode</a> is active!</b>
217 You will likely have problems caused by this. You may need to make the
218 'images' subdirectory writable or specify a TMP environment variable pointing to
219 a writable temporary directory owned by you, since safe mode breaks the system
220 temporary directory.</li>
221 <?php
222 }
223
224 $sapi = php_sapi_name();
225 $conf->prettyURLs = true;
226 print "<li>PHP server API is $sapi; ";
227 switch( $sapi ) {
228 case "apache":
229 case "apache2handler":
230 print "ok, using pretty URLs (<tt>index.php/Page_Title</tt>)";
231 break;
232 case "cgi":
233 case "cgi-fcgi":
234 case "apache2filter":
235 print "using ugly URLs (<tt>index.php?title=Page_Title</tt>)";
236 $conf->prettyURLs = false;
237 break;
238 default:
239 print "unknown; using pretty URLs (<tt>index.php/Page_Title</tt>), if you have trouble change this in <tt>LocalSettings.php</tt>";
240 }
241 print "</li>\n";
242
243 $conf->xml = function_exists( "utf8_encode" );
244 if( $conf->xml ) {
245 print "<li>Have XML / Latin1-UTF-8 conversion support.</li>\n";
246 } else {
247 dieout( "PHP's XML module is missing; the wiki requires functions in
248 this module and won't work in this configuration.
249 If you're running Mandrake, install the php-xml package." );
250 }
251
252 $memlimit = ini_get( "memory_limit" );
253 $conf->raiseMemory = false;
254 if( empty( $memlimit ) ) {
255 print "<li>PHP is configured with no <tt>memory_limit</tt>.</li>\n";
256 } else {
257 print "<li>PHP's <tt>memory_limit</tt> is " . htmlspecialchars( $memlimit ) . ". <b>If this is too low, installation may fail!</b> ";
258 $n = IntVal( $memlimit );
259 if( preg_match( '/^([0-9]+)[Mm]$/', trim( $memlimit ), $m ) ) {
260 $n = IntVal( $m[1] * (1024*1024) );
261 }
262 if( $n < 20*1024*1024 ) {
263 print "Attempting to raise limit to 20M... ";
264 if( false === ini_set( "memory_limit", "20M" ) ) {
265 print "failed.";
266 } else {
267 $conf->raiseMemory = true;
268 print "ok.";
269 }
270 }
271 print "</li>\n";
272 }
273
274 $conf->zlib = function_exists( "gzencode" );
275 if( $conf->zlib ) {
276 print "<li>Have zlib support; enabling output compression.</li>\n";
277 } else {
278 print "<li>No zlib support.</li>\n";
279 }
280
281 $conf->turck = function_exists( 'mmcache_get' );
282 if ( $conf->turck ) {
283 print "<li><a href=\"http://turck-mmcache.sourceforge.net/\">Turck MMCache</a> installed</li>\n";
284 } else {
285 print "<li><a href=\"http://turck-mmcache.sourceforge.net/\">Turck MMCache</a> not installed, " .
286 "can't use object caching functions</li>\n";
287 }
288
289 $conf->ImageMagick = false;
290 $imcheck = array( "/usr/bin", "/usr/local/bin", "/sw/bin", "/opt/local/bin" );
291 foreach( $imcheck as $dir ) {
292 $im = "$dir/convert";
293 if( file_exists( $im ) ) {
294 print "<li>Found ImageMagick: <tt>$im</tt>; image thumbnailing will be enabled if you enable uploads.</li>\n";
295 $conf->ImageMagick = $im;
296 break;
297 }
298 }
299
300 $conf->HaveGD = function_exists( "imagejpeg" );
301 if( $conf->HaveGD ) {
302 print "<li>Found GD graphics library built-in";
303 if( !$conf->ImageMagick ) {
304 print ", image thumbnailing will be enabled if you enable uploads";
305 }
306 print ".</li>\n";
307 } else {
308 if( !$conf->ImageMagick ) {
309 print "<li>Couldn't find GD library or ImageMagick; image thumbnailing disabled.</li>\n";
310 }
311 }
312
313 $conf->UseImageResize = $conf->HaveGD || $conf->ImageMagick;
314
315 # $conf->IP = "/Users/brion/Sites/inplace";
316 $conf->IP = dirname( dirname( __FILE__ ) );
317 print "<li>Installation directory: <tt>" . htmlspecialchars( $conf->IP ) . "</tt></li>\n";
318
319 # $conf->ScriptPath = "/~brion/inplace";
320 $conf->ScriptPath = preg_replace( '{^(.*)/config.*$}', '$1', $_SERVER["REQUEST_URI"] );
321 print "<li>Script URI path: <tt>" . htmlspecialchars( $conf->ScriptPath ) . "</tt></li>\n";
322
323 $conf->posted = ($_SERVER["REQUEST_METHOD"] == "POST");
324
325 $conf->Sitename = ucfirst( importPost( "Sitename", "" ) );
326 $conf->EmergencyContact = importPost( "EmergencyContact", $_SERVER["SERVER_ADMIN"] );
327 $conf->DBserver = importPost( "DBserver", "localhost" );
328 $conf->DBname = importPost( "DBname", "wikidb" );
329 $conf->DBuser = importPost( "DBuser", "wikiuser" );
330 $conf->DBpassword = importPost( "DBpassword" );
331 $conf->DBpassword2 = importPost( "DBpassword2" );
332 $conf->RootPW = importPost( "RootPW" );
333 $conf->LanguageCode = importPost( "LanguageCode", "en" );
334 $conf->SysopName = importPost( "SysopName", "WikiSysop" );
335 $conf->SysopPass = importPost( "SysopPass" );
336 $conf->SysopPass2 = importPost( "SysopPass2" );
337
338 /* Check for validity */
339 $errs = array();
340
341 if( $conf->Sitename == "" || $conf->Sitename == "MediaWiki" || $conf->Sitename == "Mediawiki" ) {
342 $errs["Sitename"] = "Must not be blank or \"MediaWiki\".";
343 }
344 if( $conf->DBuser == "" ) {
345 $errs["DBuser"] = "Must not be blank";
346 }
347 if( $conf->DBpassword == "" ) {
348 $errs["DBpassword"] = "Must not be blank";
349 }
350 if( $conf->DBpassword != $conf->DBpassword2 ) {
351 $errs["DBpassword2"] = "Passwords don't match!";
352 }
353
354 if( $conf->SysopPass == "" ) {
355 $errs["SysopPass"] = "Must not be blank";
356 }
357 if( $conf->SysopPass != $conf->SysopPass2 ) {
358 $errs["SysopPass2"] = "Passwords don't match!";
359 }
360
361 $conf->License = importRequest( "License", "none" );
362 if( $conf->License == "gfdl" ) {
363 $conf->RightsUrl = "http://www.gnu.org/copyleft/fdl.html";
364 $conf->RightsText = "GNU Free Documentation License 1.2";
365 $conf->RightsCode = "gfdl";
366 $conf->RightsIcon = '${wgStylePath}/common/images/gnu-fdl.png';
367 } elseif( $conf->License == "none" ) {
368 $conf->RightsUrl = $conf->RightsText = $conf->RightsCode = $conf->RightsIcon = "";
369 } else {
370 $conf->RightsUrl = importRequest( "RightsUrl", "" );
371 $conf->RightsText = importRequest( "RightsText", "" );
372 $conf->RightsCode = importRequest( "RightsCode", "" );
373 $conf->RightsIcon = importRequest( "RightsIcon", "" );
374 }
375
376 $conf->Shm = importRequest( "Shm", "none" );
377 $conf->MCServers = importRequest( "MCServers" );
378
379 /* Test memcached servers */
380
381 if ( $conf->Shm == 'memcached' && $conf->MCServers ) {
382 $conf->MCServerArray = array_map( 'trim', explode( ',', $conf->MCServers ) );
383 foreach ( $conf->MCServerArray as $server ) {
384 $error = testMemcachedServer( $server );
385 if ( $error ) {
386 $errs["MCServers"] = $error;
387 break;
388 }
389 }
390 } else if ( $conf->Shm == 'memcached' ) {
391 $errs["MCServers"] = "Please specify at least one server if you wish to use memcached";
392 }
393
394 if( $conf->posted && ( 0 == count( $errs ) ) ) {
395 do { /* So we can 'continue' to end prematurely */
396 $conf->Root = ($conf->RootPW != "");
397
398 /* Load up the settings and get installin' */
399 $local = writeLocalSettings( $conf );
400 $wgCommandLineMode = false;
401 chdir( ".." );
402 eval($local);
403 $wgDBadminuser = "root";
404 $wgDBadminpassword = $conf->RootPW;
405 $wgCommandLineMode = true;
406 $wgUseDatabaseMessages = false; /* FIXME: For database failure */
407 require_once( "includes/Setup.php" );
408 chdir( "config" );
409
410 require_once( "../maintenance/InitialiseMessages.inc" );
411
412 $wgTitle = Title::newFromText( "Installation script" );
413 $wgDatabase = Database::newFromParams( $wgDBserver, "root", $conf->RootPW, "", 1 );
414 $wgDatabase->mIgnoreErrors = true;
415
416 @$myver = mysql_get_server_info( $wgDatabase->mConn );
417 if( $myver ) {
418 $conf->Root = true;
419 print "<li>Connected as root (automatic)</li>\n";
420 } else {
421 print "<li>MySQL error " . ($err = mysql_errno() ) .
422 ": " . htmlspecialchars( mysql_error() );
423 $ok = false;
424 switch( $err ) {
425 case 1045:
426 case 2000:
427 if( $conf->Root ) {
428 $errs["RootPW"] = "Check password";
429 } else {
430 print "<li>Trying regular user...\n";
431 /* Try the regular user... */
432 $wgDBadminuser = $wgDBuser;
433 $wgDBadminpassword = $wgDBpassword;
434 $wgDatabase = Database::newFromParams( $wgDBserver, $wgDBuser, $wgDBpassword, "", 1 );
435 $wgDatabase->isOpen();
436 $wgDatabase->mIgnoreErrors = true;
437 @$myver = mysql_get_server_info( $wgDatabase->mConn );
438 if( !$myver ) {
439 $errs["DBuser"] = "Check name/pass";
440 $errs["DBpassword"] = "or enter root";
441 $errs["DBpassword2"] = "password below";
442 $errs["RootPW"] = "Got root?";
443 print " need password.</li>\n";
444 } else {
445 $conf->Root = false;
446 $conf->RootPW = "";
447 print " ok.</li>\n";
448 # And keep going...
449 $ok = true;
450 }
451 break;
452 }
453 case 2002:
454 case 2003:
455 $errs["DBserver"] = "Connection failed";
456 break;
457 default:
458 $errs["DBserver"] = "Couldn't connect to database";
459 break;
460 }
461 if( !$ok ) continue;
462 }
463
464 if ( !$wgDatabase->isOpen() ) {
465 $errs["DBserver"] = "Couldn't connect to database";
466 continue;
467 }
468
469 print "<li>Connected to database... $myver";
470 if( version_compare( $myver, "4.0.0" ) >= 0 ) {
471 print "; enabling MySQL 4 enhancements";
472 $conf->DBmysql4 = true;
473 $local = writeLocalSettings( $conf );
474 }
475 print "</li>\n";
476
477 @$sel = mysql_select_db( $wgDBname, $wgDatabase->mConn );
478 if( $sel ) {
479 print "<li>Database <tt>" . htmlspecialchars( $wgDBname ) . "</tt> exists</li>\n";
480 } else {
481 $res = $wgDatabase->query( "CREATE DATABASE `$wgDBname`" );
482 if( !$res ) {
483 print "<li>Couldn't create database <tt>" .
484 htmlspecialchars( $wgDBname ) .
485 "</tt>; try with root access or check your username/pass.</li>\n";
486 $errs["RootPW"] = "&lt;- Enter";
487 continue;
488 }
489 print "<li>Created database <tt>" . htmlspecialchars( $wgDBname ) . "</tt></li>\n";
490 }
491
492 $wgDatabase->selectDB( $wgDBname );
493
494 if( $wgDatabase->tableExists( "cur" ) ) {
495 print "<li>There are already MediaWiki tables in this database. Checking if updates are needed...</li>\n";
496
497 # Create user if required
498 if ( $conf->Root ) {
499 $conn = Database::newFromParams( $wgDBserver, $wgDBuser, $wgDBpassword, $wgDBname, 1 );
500 if ( $conn->isOpen() ) {
501 print "<li>DB user account ok</li>\n";
502 $conn->close();
503 } else {
504 print "<li>Granting user permissions...</li>\n";
505 dbsource( "../maintenance/users.sql", $wgDatabase );
506 }
507 }
508 print "<pre>\n";
509 chdir( ".." );
510 flush();
511 do_all_updates();
512 chdir( "config" );
513
514 print "</pre>\n";
515 print "<li>Finished update checks.</li>\n";
516 } else {
517 # FIXME: Check for errors
518 print "<li>Creating tables...";
519 dbsource( "../maintenance/tables.sql", $wgDatabase );
520 dbsource( "../maintenance/interwiki.sql", $wgDatabase );
521 dbsource( "../maintenance/archives/patch-userlevels-defaultgroups.sql", $wgDatabase );
522 print " done.</li>\n";
523
524 print "<li>Initializing data...";
525 $wgDatabase->query( "INSERT INTO site_stats (ss_row_id,ss_total_views," .
526 "ss_total_edits,ss_good_articles) VALUES (1,0,0,0)" );
527 # setting up the db user
528 if( $conf->Root ) {
529 print "<li>Granting user permissions...</li>\n";
530 dbsource( "../maintenance/users.sql", $wgDatabase );
531 }
532
533 if( $conf->SysopName ) {
534 $u = User::newFromName( $conf->getSysopName() );
535 if ( 0 == $u->idForName() ) {
536 $u->addToDatabase();
537 $u->setPassword( $conf->getSysopPass() );
538 $u->addRight( "sysop" );
539 $u->addRight( "bureaucrat" );
540 $u->saveSettings();
541 print "<li>Created sysop account <tt>" .
542 htmlspecialchars( $conf->SysopName ) . "</tt>.</li>\n";
543 } else {
544 print "<li>Could not create user - already exists!</li>\n";
545 }
546 } else {
547 print "<li>Skipped sysop account creation, no name given.</li>\n";
548 }
549
550 print "<li>Initialising log pages...";
551 $logs = array(
552 "uploadlogpage" => "uploadlogpagetext",
553 "dellogpage" => "dellogpagetext",
554 "protectlogpage" => "protectlogtext",
555 "blocklogpage" => "blocklogtext"
556 );
557 $metaNamespace = Namespace::getWikipedia();
558 $now = wfTimestampNow();
559 $won = wfInvertTimestamp( $now );
560 foreach( $logs as $page => $text ) {
561 $logTitle = $wgDatabase->strencode( $wgLang->ucfirst( str_replace( " ", "_", wfMsgNoDB( $page ) ) ) );
562 $logText = $wgDatabase->strencode( wfMsgNoDB( $text ) );
563 $wgDatabase->query( "INSERT INTO cur (cur_namespace,cur_title,cur_text," .
564 "cur_restrictions,cur_timestamp,inverse_timestamp,cur_touched) " .
565 "VALUES ($metaNamespace,'$logTitle','$logText','sysop','$now','$won','$now')" );
566 }
567 print "</li>\n";
568
569 $titleobj = Title::newFromText( wfMsgNoDB( "mainpage" ) );
570 $title = $titleobj->getDBkey();
571 $sql = "INSERT INTO cur (cur_namespace,cur_title,cur_text,cur_timestamp,inverse_timestamp,cur_touched,cur_user,cur_user_text) " .
572 "VALUES (0,'$title','" .
573 wfStrencode( wfMsg( "mainpagetext" ) . "\n\n" . wfMsg( "mainpagedocfooter" ) ) .
574 "','$now','$won','$now',0,'MediaWiki default')";
575 $wgDatabase->query( $sql, $fname );
576
577 print "<li><pre>";
578 initialiseMessages();
579 print "</pre></li>\n";
580 }
581
582 /* Write out the config file now that all is well */
583 print "<p>Creating LocalSettings.php...</p>\n\n";
584 $localSettings = "<" . "?php$endl$local$endl?" . ">";
585
586 if( version_compare( phpversion(), "4.3.2" ) >= 0 ) {
587 $xt = "xt"; # Refuse to overwrite an existing file
588 } else {
589 $xt = "wt"; # 'x' is not available prior to PHP 4.3.2. We did check above, but race conditions blah blah
590 }
591 $f = fopen( "LocalSettings.php", $xt );
592
593 if( $f == false ) {
594 dieout( "<p>Couldn't write out LocalSettings.php. Check that the directory permissions are correct and that there isn't already a file of that name here...</p>\n" .
595 "<p>Here's the file that would have been written, try to paste it into place manually:</p>\n" .
596 "<pre>\n" . htmlspecialchars( $localSettings ) . "</pre>\n" );
597 }
598 if(fwrite( $f, $localSettings ) ) {
599 fclose( $f );
600
601 print "<p>Success! Move the config/LocalSettings.php file into the parent directory, then follow
602 <a href='{$conf->ScriptPath}/index.php'>this link</a> to your wiki.</p>\n";
603 } else {
604 fclose( $f );
605 die("<p class='error'>An error occured while writing the config/LocalSettings.php file. Check user rights and disk space then try again.</p>\n");
606
607 }
608
609 } while( false );
610 }
611 ?>
612 </ul>
613
614
615 <?php
616
617 if( count( $errs ) ) {
618 /* Display options form */
619
620 if( $conf->posted ) {
621 echo "<p class='error'>Something's not quite right yet; make sure everything below is filled out correctly.</p>\n";
622 }
623 ?>
624
625 <form name="config" method="post">
626
627
628 <h2>Site config</h2>
629
630 <dl class="setup">
631 <dd>
632 <?php
633 aField( $conf, "Sitename", "Site name:" );
634 ?>
635 </dd>
636 <dt>
637 Your site name should be a relatively short word. It'll appear as the namespace
638 name for 'meta' pages as well as throughout the user interface. Good site names
639 are things like "<a href="http://www.wikipedia.org/">Wikipedia</a>" and
640 "<a href="http://openfacts.berlios.de/">OpenFacts</a>"; avoid punctuation,
641 which may cause problems.
642 </dt>
643
644 <dd>
645 <?php
646 aField( $conf, "EmergencyContact", "Contact e-mail" );
647 ?>
648 </dd>
649 <dt>
650 This will be used as the return address for password reminders and
651 may be displayed in some error conditions so visitors can get in
652 touch with you.
653 </dt>
654
655 <dd>
656 <label class='column' for="LanguageCode">Language</label>
657 <select id="LanguageCode" name="LanguageCode">
658 <?php
659 $list = getLanguageList();
660 foreach( $list as $code => $name ) {
661 $sel = ($code == $conf->LanguageCode) ? 'selected="selected"' : '';
662 echo "\t\t<option value=\"$code\" $sel>$name</option>\n";
663 }
664 ?>
665 </select>
666 </dd>
667 <dt>
668 You may select the language for the user interface of the wiki...
669 Some localizations are less complete than others. This also controls
670 the character encoding; Unicode is more flexible, but Latin-1 may be
671 more compatible with older browsers for some languages. Unicode will
672 be used where not specified otherwise.
673 </dt>
674
675 <dd>
676 <label class='column'>Copyright/license metadata</label>
677 <div>Select one:</div>
678
679 <ul class="plain">
680 <li><?php aField( $conf, "License", "no license metadata", "radio", "none" ); ?></li>
681 <li><?php aField( $conf, "License", "GNU Free Documentation License 1.2 (Wikipedia-compatible)", "radio", "gfdl" ); ?></li>
682 <li><?php
683 aField( $conf, "License", "a Creative Commons license...", "radio", "cc" );
684 $partner = "MediaWiki";
685 $exit = urlencode( "$wgServer{$conf->ScriptPath}/config/index.php?License=cc&RightsUrl=[license_url]&RightsText=[license_name]&RightsCode=[license_code]&RightsIcon=[license_button]" );
686 $icon = urlencode( "$wgServer$wgUploadPath/wiki.png" );
687 $ccApp = htmlspecialchars( "http://creativecommons.org/license/?partner=$partner&exit_url=$exit&partner_icon_url=$icon" );
688 print "<a href=\"$ccApp\">choose</a>";
689 ?> (link will wipe out any other data in this form!)
690 <?php if( $conf->License == "cc" ) { ?>
691 <ul>
692 <li><?php aField( $conf, "RightsIcon", "<img src=\"" . htmlspecialchars( $conf->RightsIcon ) . "\" alt='icon' />", "hidden" ); ?></li>
693 <li><?php aField( $conf, "RightsText", htmlspecialchars( $conf->RightsText ), "hidden" ); ?></li>
694 <li><?php aField( $conf, "RightsCode", "code: " . htmlspecialchars( $conf->RightsCode ), "hidden" ); ?></li>
695 <li><?php aField( $conf, "RightsUrl", "<a href=\"" . htmlspecialchars( $conf->RightsUrl ) . "\">" . htmlspecialchars( $conf->RightsUrl ) . "</a>", "hidden" ); ?></li>
696 </ul>
697 <?php } ?>
698 </li>
699 </ul>
700 </dd>
701 <dt>
702 MediaWiki can include a basic license notice, icon, and machine-readable
703 copyright metadata if your wiki's content is to be licensed under
704 the GNU FDL or a Creative Commons license. If you're not sure, leave
705 it at "none".
706 </dt>
707
708
709 <dd>
710 <?php aField( $conf, "SysopName", "Sysop account name:", "" ) ?>
711 </dd>
712 <dd>
713 <?php aField( $conf, "SysopPass", "password:", "password" ) ?>
714 </dd>
715 <dd>
716 <?php aField( $conf, "SysopPass2", "again:", "password" ) ?>
717 </dd>
718 <dt>
719 A sysop user account can lock or delete pages, block problematic IP
720 addresses from editing, and other maintenance tasks. If creating a new
721 wiki database, a sysop account will be created with the given name
722 and password.
723 </dt>
724
725 <dd>
726 <label class='column'>Shared memory caching</label>
727 <div>Select one:</div>
728
729 <ul class="plain">
730 <li><?php aField( $conf, "Shm", "no caching", "radio", "none" ); ?></li>
731 <?php
732 if ( $conf->turck ) {
733 echo "<li>";
734 aField( $conf, "Shm", "Turck MMCache", "radio", "turck" );
735 echo "</li>";
736 }
737 ?>
738 <li><?php aField( $conf, "Shm", "Memcached", "radio", "memcached" ); ?></li>
739 <li><?php aField( $conf, "MCServers", "Memcached servers", "" ) ?></li>
740 </ul>
741 </dd>
742 <dt>
743 Using a shared memory system such as Turck MMCache or Memcached will speed
744 up MediaWiki significantly. Memcached is the best solution but needs to be
745 installed. Specify the server addresses and ports in a comma-separted list. Only
746 use Turck shared memory if the wiki will be running on a single Apache server.
747 </dl>
748
749 <h2>Database config</h2>
750
751 <dl class="setup">
752 <dd><?php
753 aField( $conf, "DBserver", "MySQL server" );
754 ?></dd>
755 <dt>
756 If your database server isn't on your web server, enter the name
757 or IP address here.
758 </dt>
759
760 <dd><?php
761 aField( $conf, "DBname", "Database name" );
762 ?></dd>
763 <dd><?php
764 aField( $conf, "DBuser", "DB username" );
765 ?></dd>
766 <dd><?php
767 aField( $conf, "DBpassword", "DB password", "password" );
768 ?></dd>
769 <dd><?php
770 aField( $conf, "DBpassword2", "again", "password" );
771 ?></dd>
772 <dt>
773 If you only have a single user account and database available,
774 enter those here. If you have database root access (see below)
775 you can specify new accounts/databases to be created.
776 </dt>
777
778
779 <dd>
780 <?php
781 aField( $conf, "RootPW", "DB root password", "password" );
782 ?>
783 </dd>
784 <dt>
785 You will only need this if the database and/or user account
786 above don't already exist.
787 Do <em>not</em> type in your machine's root password! MySQL
788 has its own "root" user with a separate password. (It might
789 even be blank, depending on your configuration.)
790 </dt>
791
792 <dd>
793 <label class='column'>&nbsp;</label>
794 <input type="submit" value="Install!" />
795 </dd>
796 </dl>
797
798
799 </form>
800
801 <?php
802 }
803
804 /* -------------------------------------------------------------------------------------- */
805
806 function writeAdminSettings( $conf ) {
807 return "
808 \$wgDBadminuser = \"{$conf->DBadminuser}\";
809 \$wgDBadminpassword = \"{$conf->DBadminpassword}\";
810 ";
811 }
812
813 function escapePhpString( $string ) {
814 return strtr( $string,
815 array(
816 "\n" => "\\n",
817 "\r" => "\\r",
818 "\t" => "\\t",
819 "\\" => "\\\\",
820 "\$" => "\\\$",
821 "\"" => "\\\""
822 ));
823 }
824
825 function writeLocalSettings( $conf ) {
826 $conf->DBmysql4 = @$conf->DBmysql4 ? 'true' : 'false';
827 $conf->UseImageResize = $conf->UseImageResize ? 'true' : 'false';
828 $conf->PasswordSender = $conf->EmergencyContact;
829 if( preg_match( '/^([a-z]+)-latin1$/', $conf->LanguageCode, $m ) ) {
830 $conf->LanguageCode = $m[1];
831 $conf->Latin1 = true;
832 } else {
833 $conf->Latin1 = false;
834 }
835 $zlib = ($conf->zlib ? "" : "# ");
836 $magic = ($conf->ImageMagick ? "" : "# ");
837 $convert = ($conf->ImageMagick ? $conf->ImageMagick : "/usr/bin/convert" );
838 $pretty = ($conf->prettyURLs ? "" : "# ");
839 $ugly = ($conf->prettyURLs ? "# " : "");
840 $rights = ($conf->RightsUrl) ? "" : "# ";
841
842 switch ( $conf->Shm ) {
843 case 'memcached':
844 $memcached = 'true';
845 $turck = '#';
846 $mcservers = var_export( $conf->MCServerArray, true );
847 break;
848 case 'turck':
849 $memcached = 'false';
850 $mcservers = 'array()';
851 $turck = '';
852 break;
853 default:
854 $memcached = 'false';
855 $mcservers = 'array()';
856 $turck = '#';
857 }
858
859
860 $file = @fopen( "/dev/urandom", "r" );
861 if ( $file ) {
862 $proxyKey = bin2hex( fread( $file, 32 ) );
863 fclose( $file );
864 } else {
865 $proxyKey = "";
866 for ( $i=0; $i<8; $i++ ) {
867 $proxyKey .= dechex(mt_rand(0, 0x7fffffff));
868 }
869 print "<li>Warning: \$wgProxyKey is insecure</li>\n";
870 }
871
872 # Add slashes to strings for double quoting
873 $slconf = array_map( "escapePhpString", get_object_vars( $conf ) );
874 if( $conf->License == 'gfdl' ) {
875 # Needs literal string interpolation for the current style path
876 $slconf['RightsIcon'] = $conf->RightsIcon;
877 }
878
879 $sep = (DIRECTORY_SEPARATOR == "\\") ? ";" : ":";
880 return "
881 # This file was automatically generated by the MediaWiki installer.
882 # If you make manual changes, please keep track in case you need to
883 # recreate them later.
884
885 \$IP = \"{$slconf['IP']}\";
886 ini_set( \"include_path\", \".$sep\$IP$sep\$IP/includes$sep\$IP/languages\" );
887 require_once( \"includes/DefaultSettings.php\" );
888
889 # If PHP's memory limit is very low, some operations may fail.
890 " . ($conf->raiseMemory ? '' : '# ' ) . "ini_set( 'memory_limit', '20M' );" . "
891
892 if ( \$wgCommandLineMode ) {
893 if ( isset( \$_SERVER ) && array_key_exists( 'REQUEST_METHOD', \$_SERVER ) ) {
894 die( \"This script must be run from the command line\\n\" );
895 }
896 } elseif ( empty( \$wgConfiguring ) ) {
897 ## Compress output if the browser supports it
898 {$zlib}if( !ini_get( 'zlib.output_compression' ) ) @ob_start( 'ob_gzhandler' );
899 }
900
901 \$wgSitename = \"{$slconf['Sitename']}\";
902
903 \$wgScriptPath = \"{$slconf['ScriptPath']}\";
904 \$wgScript = \"\$wgScriptPath/index.php\";
905 \$wgRedirectScript = \"\$wgScriptPath/redirect.php\";
906
907 ## If using PHP as a CGI module, use the ugly URLs
908 {$pretty}\$wgArticlePath = \"\$wgScript/\$1\";
909 {$ugly}\$wgArticlePath = \"\$wgScript?title=\$1\";
910
911 \$wgStylePath = \"\$wgScriptPath/skins\";
912 \$wgStyleDirectory = \"\$IP/skins\";
913 \$wgLogo = \"\$wgStylePath/common/images/wiki.png\";
914
915 \$wgUploadPath = \"\$wgScriptPath/images\";
916 \$wgUploadDirectory = \"\$IP/images\";
917
918 \$wgEmergencyContact = \"{$slconf['EmergencyContact']}\";
919 \$wgPasswordSender = \"{$slconf['PasswordSender']}\";
920
921 \$wgDBserver = \"{$slconf['DBserver']}\";
922 \$wgDBname = \"{$slconf['DBname']}\";
923 \$wgDBuser = \"{$slconf['DBuser']}\";
924 \$wgDBpassword = \"{$slconf['DBpassword']}\";
925
926 ## To allow SQL queries through the wiki's Special:Askaql page,
927 ## uncomment the next lines. THIS IS VERY INSECURE. If you want
928 ## to allow semipublic read-only SQL access for your sysops,
929 ## you should define a MySQL user with limited privileges.
930 ## See MySQL docs: http://www.mysql.com/doc/en/GRANT.html
931 #
932 # \$wgAllowSysopQueries = true;
933 # \$wgDBsqluser = \"sqluser\";
934 # \$wgDBsqlpassword = \"sqlpass\";
935
936 \$wgDBmysql4 = \$wgEnablePersistentLC = {$conf->DBmysql4};
937
938 ## Shared memory settings
939 \$wgUseMemcached = $memcached;
940 \$wgMemCachedServers = $mcservers;
941 {$turck}\$wgUseTurckShm = function_exists( 'mmcache_get' ) && php_sapi_name() == 'apache';
942
943 ## To enable image uploads, make sure the 'images' directory
944 ## is writable, then uncomment this:
945 # \$wgDisableUploads = false;
946 \$wgUseImageResize = {$conf->UseImageResize};
947 {$magic}\$wgUseImageMagick = true;
948 {$magic}\$wgImageMagickConvertCommand = \"{$convert}\";
949
950 ## If you have the appropriate support software installed
951 ## you can enable inline LaTeX equations:
952 # \$wgUseTeX = true;
953 \$wgMathPath = \"{\$wgUploadPath}/math\";
954 \$wgMathDirectory = \"{\$wgUploadDirectory}/math\";
955 \$wgTmpDirectory = \"{\$wgUploadDirectory}/tmp\";
956
957 \$wgLocalInterwiki = \$wgSitename;
958
959 \$wgLanguageCode = \"{$slconf['LanguageCode']}\";
960 \$wgUseLatin1 = " . ($conf->Latin1 ? 'true' : 'false') . ";\n
961
962 \$wgProxyKey = \"$proxyKey\";
963
964 ## Default skin: you can change the default skin. Use the internal symbolic
965 ## names, ie 'standard', 'nostalgia', 'cologneblue', 'monobook':
966 # \$wgDefaultSkin = 'monobook';
967
968 ## For attaching licensing metadata to pages, and displaying an
969 ## appropriate copyright notice / icon. GNU Free Documentation
970 ## License and Creative Commons licenses are supported so far.
971 {$rights}\$wgEnableCreativeCommonsRdf = true;
972 \$wgRightsPage = \"\"; # Set to the title of a wiki page that describes your license/copyright
973 \$wgRightsUrl = \"{$slconf['RightsUrl']}\";
974 \$wgRightsText = \"{$slconf['RightsText']}\";
975 \$wgRightsIcon = \"{$slconf['RightsIcon']}\";
976 # \$wgRightsCode = \"{$slconf['RightsCode']}\"; # Not yet used
977 ";
978 }
979
980 function dieout( $text ) {
981 die( $text . "\n\n</body>\n</html>" );
982 }
983
984 function importVar( &$var, $name, $default = "" ) {
985 if( isset( $var[$name] ) ) {
986 $retval = $var[$name];
987 if ( get_magic_quotes_gpc() ) {
988 $retval = stripslashes( $retval );
989 }
990 } else {
991 $retval = $default;
992 }
993 return $retval;
994 }
995
996 function importPost( $name, $default = "" ) {
997 return importVar( $_POST, $name, $default );
998 }
999
1000 function importRequest( $name, $default = "" ) {
1001 return importVar( $_REQUEST, $name, $default );
1002 }
1003
1004 function aField( &$conf, $field, $text, $type = "", $value = "" ) {
1005 if( $type != "" ) {
1006 $xtype = "type=\"$type\"";
1007 } else {
1008 $xtype = "";
1009 }
1010
1011 if(!(isset($id)) or ($id == "") ) $id = $field;
1012 $nolabel = ($type == "radio") || ($type == "hidden");
1013 if( $nolabel ) {
1014 echo "\t\t<label>";
1015 } else {
1016 echo "\t\t<label class='column' for=\"$id\">$text</label>\n";
1017 }
1018
1019 if( $type == "radio" && $value == $conf->$field ) {
1020 $checked = "checked='checked'";
1021 } else {
1022 $checked = "";
1023 }
1024 echo "\t\t<input $xtype name=\"$field\" id=\"$id\" $checked value=\"";
1025 if( $type == "radio" ) {
1026 echo htmlspecialchars( $value );
1027 } else {
1028 echo htmlspecialchars( $conf->$field );
1029 }
1030 echo "\" />\n";
1031 if( $nolabel ) {
1032 echo " $text</label>\n";
1033 }
1034
1035 global $errs;
1036 if(isset($errs[$field])) echo "<span class='error'>" . $errs[$field] . "</span>\n";
1037 }
1038
1039 function getLanguageList() {
1040 global $wgLanguageNames;
1041 if( !isset( $wgLanguageNames ) ) {
1042 $wgContLanguageCode = "xxx";
1043 function wfLocalUrl( $x ) { return $x; }
1044 function wfLocalUrlE( $x ) { return $x; }
1045 require_once( "../languages/Names.php" );
1046 }
1047
1048 $codes = array();
1049 $latin1 = array( "da", "de", "en", "es", "fr", "nl", "sv" );
1050
1051 $d = opendir( "../languages" );
1052 while( false !== ($f = readdir( $d ) ) ) {
1053 if( preg_match( '/Language([A-Z][a-z_]+)\.php$/', $f, $m ) ) {
1054 $code = str_replace( '_', '-', strtolower( $m[1] ) );
1055 if( in_array( $code, $latin1 ) ) {
1056 $codes[$code] = "$code - " . $wgLanguageNames[$code] . " - Unicode";
1057 $codes[$code.'-latin1'] = "$code - " . $wgLanguageNames[$code] . " - Latin-1";
1058 } else {
1059 $codes[$code] = "$code - " . $wgLanguageNames[$code];
1060 }
1061 }
1062 }
1063 closedir( $d );
1064 ksort( $codes );
1065 return $codes;
1066 }
1067
1068 # Test a memcached server
1069 function testMemcachedServer( $server ) {
1070 $hostport = explode(":", $server);
1071 $errstr = false;
1072 $fp = false;
1073 if ( !function_exists( 'fsockopen' ) ) {
1074 $errstr = "Can't connect to memcached, fsockopen() not present";
1075 }
1076 if ( !$errstr && count( $hostport ) != 2 ) {
1077 $errstr = 'Please specify host and port';
1078 var_dump( $hostport );
1079 }
1080 if ( !$errstr ) {
1081 list( $host, $port ) = $hostport;
1082 $errno = 0;
1083 $fsockerr = '';
1084
1085 $fp = @fsockopen( $host, $port, $errno, $fsockerr, 1.0 );
1086 if ( $fp === false ) {
1087 $errstr = "Cannot connect to memcached on $host:$port : $fsockerr";
1088 }
1089 }
1090 if ( !$errstr ) {
1091 $command = "version\r\n";
1092 $bytes = fwrite( $fp, $command );
1093 if ( $bytes != strlen( $command ) ) {
1094 $errstr = "Cannot write to memcached socket on $host:$port";
1095 }
1096 }
1097 if ( !$errstr ) {
1098 $expected = "VERSION ";
1099 $response = fread( $fp, strlen( $expected ) );
1100 if ( $response != $expected ) {
1101 $errstr = "Didn't get correct memcached response from $host:$port";
1102 }
1103 }
1104 if ( $fp ) {
1105 fclose( $fp );
1106 }
1107 if ( !$errstr ) {
1108 echo "<li>Connected to memcached on $host:$port successfully";
1109 }
1110 return $errstr;
1111 }
1112 ?>
1113
1114 </body>
1115 </html>